package com.adgox.tiantianbiting.listen.index;

import android.util.Log;

import com.adgox.tiantianbiting.bean.BaseResponseBean;
import com.adgox.tiantianbiting.bean.HistoryBean;
import com.adgox.tiantianbiting.bean.PageBean;
import com.adgox.tiantianbiting.bean.SubProgramBean;
import com.adgox.tiantianbiting.bean.UserInfo;
import com.adgox.tiantianbiting.net.callback.JsonCallback;
import com.adgox.tiantianbiting.utils.ApiConstant;
import com.adgox.tiantianbiting.utils.DialogUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.rae.swift.session.SessionManager;

import java.util.List;

/**
 * Created by tang on 2019/1/8.
 */

public class ListenPresenterImpl implements ListenContract.Presenter {

    private ListenContract.View mView;

    public ListenPresenterImpl(ListenContract.View mView) {
        this.mView = mView;
        mView.setPresenter(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void getHistroy(int startPoint,int maxPage,int userId) {
        OkGo.<BaseResponseBean<PageBean<HistoryBean>>>get(ApiConstant.BASE_URL+ApiConstant.GET_HISTORY_AND_COLLECT+userId+"/0")
                .params("startPoint",startPoint)
                .params("maxPage",maxPage)
                .execute(new JsonCallback<BaseResponseBean<PageBean<HistoryBean>>>() {
                    @Override
                    public void onSuccess(Response<BaseResponseBean<PageBean<HistoryBean>>> response) {
                        DialogUtils.dismiss();
                        if (response.body().getData() == null){
                            mView.onGetHistoryFailed(response.body().getMessage());
                            return;
                        }
                        mView.onSetHistory(response.body().getData());
                    }
                });
    }

    @Override
    public void getCollect(int startPoint, int maxPage,int userId) {
        OkGo.<BaseResponseBean<PageBean<SubProgramBean>>>get(ApiConstant.BASE_URL+ApiConstant.GET_HISTORY_AND_COLLECT+userId+"/2")
                .params("startPoint",startPoint)
                .params("maxPage",maxPage)
                .execute(new JsonCallback<BaseResponseBean<PageBean<SubProgramBean>>>() {
                    @Override
                    public void onSuccess(Response<BaseResponseBean<PageBean<SubProgramBean>>> response) {
                        DialogUtils.dismiss();
                        if (response.body().getData() == null){
                            mView.onGetCollectFailed(response.body().getMessage());
                            return;
                        }
                        mView.onSetCollect(response.body().getData());
                    }
                });
    }

    @Override
    public void getRecommend(int userId) {
        OkGo.<BaseResponseBean<List<SubProgramBean>>>get(ApiConstant.BASE_URL+ApiConstant.GET_RECOMMEND)
                .params("userId",userId)
                .execute(new JsonCallback<BaseResponseBean<List<SubProgramBean>>>() {
                    @Override
                    public void onSuccess(Response<BaseResponseBean<List<SubProgramBean>>> response) {
                        if ("0".equals(response.body().getCode())||response.body().getData()!=null){
                            mView.onSetRecommend(response.body().getData());
                            return;
                        }
                        mView.onGetRecommendFailed(response.body().getMessage());
                    }
                });
    }
}
